# -*- coding: utf-8 -*-
#
# Copyright (C) 2009, Aşkın Yollu <askin@askin.ws>
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# Please read the COPYING file.
#

import gettext
gettext.bindtextdomain('myapplication', '/path/to/my/language/directory')
gettext.textdomain('myapplication')
_ = gettext.gettext

from PyQt4 import QtGui, QtCore
from ui_rotate import Ui_MainWindow
from ConvertImage import ConvertImage

class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)

        self.setupUi(self)
        self.images = []
        self.comboBoxSignal = 0

        self.connect(self.pbApply, QtCore.SIGNAL("clicked(bool)"), self.rotateImages)
        self.connect(self.pbCancel, QtCore.SIGNAL("clicked(bool)"), self.quit)
        self.connect(self.cbSelectAngle, QtCore.SIGNAL('currentIndexChanged(int)'), self.comboxBoxUpdated)

    def rotateImages(self):
        for image in self.images:
            self.rotateImg(image)

    def rotateImg(self, image):
        if self.rbCustomAngle.isChecked():
            image.setAngle(self.sbAngle.value())

        if self.rbAppend.isChecked():
            image.setAppend(str(self.leAppend.text()))

        if self.rbRotateInPlace.isChecked():
            image.setAppend('')

        if self.rbSelectAngle.isChecked():
            if self.comboBoxSignal == 0:
                image.setAngle(270)
            elif self.comboBoxSignal == 1:
                image.setAngle(90)
            elif self.comboBoxSignal == 2:
                image.setAngle(180)
            else:
                image.setAngle(270)

        image.rotateImage()
        print("It's Done Mannn!!!")
        self.close()

    def comboxBoxUpdated(self, index):
        self.comboBoxSignal = index
        print("comboBox index: %d" % index)

    def quit(self):
        self.close()
